#!/bin/sh
################################################################################
#
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
# File: cpuisolation04.sh
#
# Description: SUB_KERNEL_CPUISOLATE_STRESS_TEST
#
# Authors:     Ma Feng - mafeng.ma@huawei.com
#
# History:     Mar 15 2022 - init scripts
#
################################################################################

source tst_oh.sh

do_setup()
{
	if [ ! -d "/sys/kernel/debug/tracing" ]; then
		mkdir /sys/kernel/debug/tracing
	fi

	if mountpoint -q /sys/kernel/debug/tracing; then
		tst_res TINFO "mountpoint -q /sys/kernel/debug/tracing"
	else
		mount -t tracefs nodev /sys/kernel/debug/tracing
		tst_res TINFO "mount -t tracefs nodev /sys/kernel/debug/tracing"
	fi
}

do_test()
{
	tst_res TINFO "Start test cpuisolation05.sh" 

	echo 1 > /sys/kernel/debug/tracing/tracing_on #enable trace
	
	echo "" >  /sys/kernel/debug/tracing/trace  #reset tarce  
	echo 1 > /sys/kernel/debug/tracing/events/sched/core_ctl_eval_need/enable 
	cat  /sys/kernel/debug/tracing/trace
	if [ ! ` wc -c /sys/kernel/debug/tracing/trace | awk '{print $1}'` == 444 ]; then 
		tst_res TINFO "core_ctl_eval_need successd"
	else 
		tst_res TINFO "core_ctl_eval_need failed"
	fi
	
	echo "" >  /sys/kernel/debug/tracing/trace  #reset tarce 	
	echo 1 > /sys/kernel/debug/tracing/events/sched/core_ctl_set_boost/enable 
	cat /sys/kernel/debug/tracing/trace
	if [ ! `wc -c /sys/kernel/debug/tracing/trace | awk '{print $1}'` == 444 ]; then		
		tst_res TINFO "core_ctl_set_boost successed"
	else 
		tst_res TINFO "core_ctl_set_boost failed"
	fi
	sleep 5
	echo "" >  /sys/kernel/debug/tracing/trace  #reset tarce 	
	echo 1 > /sys/kernel/debug/tracing/events/sched/core_ctl_set_busy/enable 
	cat /sys/kernel/debug/tracing/trace
	if [ ! `wc -c  /sys/kernel/debug/tracing/trace | awk '{print $1}'` == 444 ]; then
		tst_res TINFO "core_ctl_set_busy successed"	
	else 
		tst_res TINFO "core_ctl_set_busy failed"
	fi
				
	echo "" >  /sys/kernel/debug/tracing/trace  #reset tarce 	
	echo 1 > /sys/kernel/debug/tracing/events/sched/core_ctl_update_nr_need/enable 
	cat /sys/kernel/debug/tracing/trace
	if [ ! `wc -c /sys/kernel/debug/tracing/trace | awk '{print $1}'` == 444  ]; then
		tst_res TINFO "core_ctl_update_nr_need successed"	
	else 
		tst_res TINFO "core_ctl_update_nr_need failed"
	fi				
	echo "" >  /sys/kernel/debug/tracing/trace
}		

do_clean()
{
	echo 0 > /sys/kernel/debug/tracing/events/sched/core_ctl_eval_need/enable #disable core_ctl_eval_need
	echo 0 > /sys/kernel/debug/tracing/events/sched/core_ctl_set_boost/enable #disable core_ctl_set_boost
	echo 0 > /sys/kernel/debug/tracing/events/sched/core_ctl_set_busy/enable #disable core_ctl_set_busy
	echo 0 > /sys/kernel/debug/tracing/events/sched/core_ctl_update_nr_need/enable #disable core_ctl_update_nr_need
	echo 0 > /sys/kernel/debug/tracing/tracing_on #disable trace
}

do_setup
do_test
do_clean
tst_exit
